home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
5
/
PIXELWOR
/
CPIXELWO.H
< prev
next >
Wrap
Text File
|
1992-01-01
|
9KB
|
197 lines
/******************************************************************************
CPixelWorld.h
Pixel World Class, Version 1.0 (SUPERCLASS = CBitMap)
__________________________________________________________________________
Ñ Description
The CPixelWorld class is a subclass of CBitMap (THINK Class Library 1.1)
designed to maintain a color offscreen drawing environment using the
standard conventions of Color QuickDraw. An offscreen color graphics
device (GDevice) and an offscreen color graphics port (CGrafPort) are
used to maintain this offscreen world. This implementation supports
standard pixel depths of 1,2,4 and 8 bits. Pixel depths of 16 and 32
are not supported since this implementation does not rely on 32-Bit
QuickDraw features. In the future, support for 16 and 32 bit pixel
depths and the offscreen GWorlds provided by 32-Bit QuickDraw can be
incorporated into a subclass of CPixelWorld called CGWorld.
Ñ Creating a Blank Pixel World
A blank pixel world is created by calling the initialization method
IPixelWorld() with a pixel depth (aPixelDepth), a bounds rectangle
(aBoundsRect), a handle to a color table (aColorTable), and NULL for
the handle to the pixel image (aPixelImage). You can pass any value
for row bytes (aRowBytes) since the value will be ignored in this case.
You should pass a color table handle (CTabHandle) in the aColorTable
parameter. The color table is copied and the copy is used for the
offscreen world. If aColorTable is NULL, then the default color table
for the desired pixel depth will be used.
*** WARNING ***
If you request a pixel depth of one and Color QuickDraw is not
available, then a blank offscreen world will be created as a standard
BitMap with a non-color graphics port (GrafPort) using the CBitMap
superclass. If you request a pixel depth greater than one and Color
QuickDraw is not available, the initialization method will fail. To
detect initialization failure call the method WorldIsOK(), which
returns the value of the instance variable worldIsOK. WorldIsOK()
will return TRUE after successful initialization, and FALSE after
initialization failure.
Ñ Creating a Pixel World with an Existing Image
A world based on an existing color or grayscale image is created by
calling the initialization method IPixelWorld() with the pixel depth of
the existing image (aPixelDepth), the bounds rectangle of the existing
image (aBoundsRect), a color table for the existing image (aColorTable),
and a handle to the pixels for the existing image (aPixelImage). In
this case, you must also pass a value for the row bytes of the pixel
image (aRowBytes).
*** IMPORTANT ***
When you create an offscreen world based on an existing pixel image,
IT IS YOUR RESPONSIBILITY TO DISPOSE OF YOUR PIXEL IMAGE. Although
CPixelWorld keeps its own handle to your pixel image in the instance
variable worldPixels, it will not dispose of the pixel image. In
contrast, when you create a blank world by passing NULL for the
aPixelImage parameter, CPixelWorld creates its own pixel image and it
will dispose of this image when the offscreen world is destroyed by
the Dispose() instance method.
When you create your own pixel image for use with an offscreen world
use a multiple of four for the row bytes of your pixel image. The
following formula will give a multiple of four for row bytes:
rowBytes = ((((long) width * pixelDepth) + 31) / 32) * 4;
A multiple of four for row bytes will give optimal performance in calls
to the QuickDraw function CopyBits() and its related functions.
*** WARNING ***
When you create an offscreen world with an existing image that has a
pixel depth greater than one, the initialization method will fail if
Color QuickDraw is not available since there is no support for images
with pixel depths greater than one without Color QuickDraw.
Ñ Drawing to the Offscreen Pixel World
If you need to draw directly to the offscreen world, you must bracket
all drawing with calls to BeginDrawing() and EndDrawing(). This will
set up the offscreen GDevice and CGrafPort for drawing. In addition,
the LockWorld() method will be called to make sure that the pixel
image is anchored down and will not move when you invoke any QuickDraw
routines. LockWorld() locks the handle to the pixel image, and then
it loads the derefernced handle into the PixMap baseAddr pointers of
both the offscreen GDevice and the offscreen CGrafPort.
Ñ Version History
__________________________________________________________
Release Version: 1.0
Release Date: January 1, 1992
Implemented By: Vincent R. Vann, Jr.
1901 Brickell Ave, B-410
Miami, Florida 33129 USA
Compuserve Address: 76530,1242
Internet Address: vvann@umbio.med.miami.edu
(129.171.65.204)
__________________________________________________________
Ñ License Agreement
All portions of this source code are property of Vincent R. Vann, Jr.
I, Vincent R. Vann, Jr., grant you the right to freely distribute this
source code and to use all or part of this source code in all software
including commercial, freeware, shareware and private applications.
However, all software that uses any part of or all of this source code
must display a copyright notice indicating that either all of or
portions of this source code are used in the software. I also grant
you permission to alter and make improvements to this source code, but
only if all modifications are returned to me by whatever means are
available, either in written or electronic form. You must also accept
that I retain the right to include any part of your modifications or
all of your modifications in future releases of this source code. The
description and version history sections above may be ammended for
documentation purposes. This license agreement and the copyright
notice below must be maintained intact and must be included with all
distributions of this source code at all times.
This implementation is based in part on material copyrighted by Apple
Computer, Inc. and Symantec Corporation.
Copyright ⌐ 1992 Vincent R. Vann, Jr. All rights reserved.
******************************************************************************/
#define _H_CPixelWorld
#include "CBitMap.h" /* Interface for its superclass */
#include "LongCoordinates.h"
class CPixelWorld : public CBitMap { /* Class Declaration */
public:
/** Instance Variables **/
Boolean worldIsOK; /* TRUE if initialized successfully */
Boolean worldHasColor; /* TRUE if have Color QuickDraw */
Boolean worldHas32BitQD; /* TRUE if have 32-Bit QuickDraw */
Boolean worldOwnsPixels; /* TRUE if world owns pixel image */
Boolean worldPixelsLocked; /* TRUE if pixel image is locked */
short worldDepth; /* Pixel depth */
LongRect worldBounds; /* Bounds rectangle */
CTabHandle worldColors; /* Color table handle */
Handle worldPixels; /* Pixel image handle */
GDHandle worldDevice; /* Offscreen GDevice handle */
CGrafPtr worldPort; /* Offscreen CGrafPort pointer */
GDHandle saveDevice; /* Saved graphics device */
/** Instance Methods **/
/** Contruction/Destruction **/
void IPixelWorld( short aPixelDepth, Rect *aBoundsRect,
CTabHandle aColorTable, Handle aPixelImage, short aRowBytes);
void IPixelWorldBW( short aPixelDepth, Rect *aBoundsRect,
Handle aPixelImage, short aRowBytes);
void IPixelWorldColor( short aPixelDepth, Rect *aBoundsRect,
CTabHandle aColorTable, Handle aPixelImage, short aRowBytes);
virtual void Dispose(void);
/** Accessing **/
virtual Boolean WorldIsOK(void);
virtual void GetBounds(LongRect *theBounds);
virtual void SetBoundsOrigin(short hOrigin, short vOrigin);
virtual Boolean PixelIsBlack(LongPt *pixelPos);
virtual Boolean GetPixelColor(LongPt *pixelPos, RGBColor *color);
virtual short GetPixelDepth(void);
virtual short GetRowBytes(void);
virtual Handle GetHandleToPixels(void);
virtual Ptr GetPointerToPixels(void);
/** Activate/Deactivate/Lock **/
virtual Boolean LockWorld(Boolean setLock);
virtual void ActivateWorld(void);
virtual void DeactivateWorld(void);
/** Image Copying **/
virtual void CopyTo(LongRect *fromRect, LongRect *toRect, RgnHandle maskRgn);
virtual void CopyFrom(LongRect *fromRect, LongRect *toRect, RgnHandle maskRgn);
/** Preparing **/
virtual void BeginDrawing(void);
virtual void EndDrawing(void);
};